6 class MergeHistoryTest
extends MediaWikiTestCase
{
9 * Make some pages to work with
11 public function addDBDataOnce() {
12 // Pages that won't actually be merged
13 $this->insertPage( 'Test' );
14 $this->insertPage( 'Test2' );
16 // Pages that will be merged
17 $this->insertPage( 'Merge1' );
18 $this->insertPage( 'Merge2' );
22 * @dataProvider provideIsValidMerge
23 * @covers MergeHistory::isValidMerge
24 * @param string $source Source page
25 * @param string $dest Destination page
26 * @param string|bool $timestamp Timestamp up to which revisions are merged (or false for all)
27 * @param string|bool $error Expected error for test (or true for no error)
29 public function testIsValidMerge( $source, $dest, $timestamp, $error ) {
30 if ( $timestamp === true ) {
31 // Although this timestamp is after the latest timestamp of both pages,
32 // MergeHistory should select the latest source timestamp up to this which should
33 // still work for the merge.
34 $timestamp = time() +
( 24 * 3600 );
36 $mh = new MergeHistory(
37 Title
::newFromText( $source ),
38 Title
::newFromText( $dest ),
41 $status = $mh->isValidMerge();
42 if ( $error === true ) {
43 $this->assertTrue( $status->isGood() );
45 $this->assertTrue( $status->hasMessage( $error ) );
49 public static function provideIsValidMerge() {
51 // for MergeHistory::isValidMerge
52 [ 'Test', 'Test2', false, true ],
53 // Timestamp of `true` is a placeholder for "in the future""
54 [ 'Test', 'Test2', true, true ],
55 [ 'Test', 'Test', false, 'mergehistory-fail-self-merge' ],
56 [ 'Nonexistant', 'Test2', false, 'mergehistory-fail-invalid-source' ],
57 [ 'Test', 'Nonexistant', false, 'mergehistory-fail-invalid-dest' ],
61 'This is obviously an invalid timestamp',
62 'mergehistory-fail-bad-timestamp'
68 * Test merge revision limit checking
69 * @covers MergeHistory::isValidMerge
71 public function testIsValidMergeRevisionLimit() {
72 $limit = MergeHistory
::REVISION_LIMIT
;
74 $mh = $this->getMockBuilder( MergeHistory
::class )
75 ->setMethods( [ 'getRevisionCount' ] )
76 ->setConstructorArgs( [
77 Title
::newFromText( 'Test' ),
78 Title
::newFromText( 'Test2' ),
81 $mh->expects( $this->once() )
82 ->method( 'getRevisionCount' )
83 ->will( $this->returnValue( $limit +
1 ) );
85 $status = $mh->isValidMerge();
86 $this->assertTrue( $status->hasMessage( 'mergehistory-fail-toobig' ) );
87 $errors = $status->getErrorsByType( 'error' );
88 $params = $errors[0]['params'];
89 $this->assertEquals( $params[0], Message
::numParam( $limit ) );
93 * Test user permission checking
94 * @covers MergeHistory::checkPermissions
96 public function testCheckPermissions() {
97 $mh = new MergeHistory(
98 Title
::newFromText( 'Test' ),
99 Title
::newFromText( 'Test2' )
102 // Sysop with mergehistory permission
103 $sysop = static::getTestSysop()->getUser();
104 $status = $mh->checkPermissions( $sysop, '' );
105 $this->assertTrue( $status->isOK() );
108 $notSysop = static::getTestUser()->getUser();
109 $status = $mh->checkPermissions( $notSysop, '' );
110 $this->assertTrue( $status->hasMessage( 'mergehistory-fail-permission' ) );
114 * Test merged revision count
115 * @covers MergeHistory::getMergedRevisionCount
117 public function testGetMergedRevisionCount() {
118 $mh = new MergeHistory(
119 Title
::newFromText( 'Merge1' ),
120 Title
::newFromText( 'Merge2' )
123 $sysop = static::getTestSysop()->getUser();
124 $mh->merge( $sysop );
125 $this->assertEquals( $mh->getMergedRevisionCount(), 1 );